#include <iostream>
#include <cmath>
#include <string>

// Function to check if a number is prime
bool f(int x) {
    for (int i = 2; i <= static_cast<int>(std::sqrt(x)) + 1; i++) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::string input;
    std::getline(std::cin, input);

    std::string c = "";
    int wrong = 0;

    // Convert the input string to a number
    std::string word;
    for (char c : input) {
        if (c == ' ') {
            if (word == "zero") {
                c += "0";
            } else if (word == "one") {
                c += "1";
            } else if (word == "two") {
                c += "2";
            } else if (word == "three") {
                c += "3";
            } else if (word == "four") {
                c += "4";
            } else if (word == "five") {
                c += "5";
            } else if (word == "six") {
                c += "6";
            } else if (word == "seven") {
                c += "7";
            } else if (word == "eight") {
                c += "8";
            } else if (word == "nine") {
                c += "9";
            } else {
                wrong = 1;
                break;
            }
            word = "";
        } else {
            word += c;
        }
    }

    if (wrong == 1 || c.length() != 3) {
        std::cout << "Wrong input" << std::endl;
    } else {
        int num = std::stoi(c);

        int nmin = 0;
        int nmax = 0;

        // Find the nearest prime number greater than the input number
        for (int i = num + 1; i < 1000; i++) {
            if (f(i)) {
                nmax = i;
                break;
            }
        }

        // Find the nearest prime number less than the input number
        for (int i = num - 1; i >= 99; i--) {
            if (f(i)) {
                nmin = i;
                break;
            }
        }

        if (num - nmin > nmax - num) {
            std::cout << nmax << std::endl;
        } else {
            std::cout << nmin << std::endl;
        }
    }

    return 0;
}